package com.elvt.server.config.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @Author 作者： elvt
 * @Data 时间：2022/5/24
 * @packageName 包路径： ybg_back_end
 * @Desciption 说明： redis配置类
 */
@Configuration
public class ReidsConfig {

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory){
    RedisTemplate<String, Object> redisTemplate=new RedisTemplate<>();
    //String类型 key序列器
    redisTemplate.setKeySerializer(new StringRedisSerializer());
        //String类型 value序列器
    redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //Hash类型 value序列器
    redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        //Hash类型 key序列器
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setConnectionFactory(factory);
    return redisTemplate;
    }
}
